{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "MMD_auto_motion_ready_CH.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BcZP1D1ONcBW",
        "colab_type": "text"
      },
      "source": [
        "# 欢迎使用Colab版本的MMD自动跟踪！（准备篇）"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BUSUZFHMNzHD",
        "colab_type": "text"
      },
      "source": [
        "该ipynb主要用于：\n",
        "\n",
        "- 什么是colab(Google Colaboratory)\n",
        "- 如何使用colab\n",
        "- 如何输入输出(Google 云盘)\n",
        "- 解决错误的办法\n",
        "- 注意事項\n",
        "- License许可\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VGsRTnpVPH9u",
        "colab_type": "text"
      },
      "source": [
        "# 1.什么是colab(Google Colaboratory)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lqhEP2J3PPqF",
        "colab_type": "text"
      },
      "source": [
        "> Colaboratory 是一个免费的 Jupyter 笔记本环境，不需要进行任何设置就可以使用，并且完全在云端运行。\n",
        "\n",
        "> 借助 Colaboratory，您可以编写和执行代码、保存和共享分析结果，以及利用强大的计算资源，所有这些都可通过浏览器免费使用。\n",
        "\n",
        "如果您使用的是Chrome或Firefox，则可以在Google云上运行MMD自动跟踪。执行结果VMD等可以下载到本地环境。\n",
        "\n",
        "由于使用方法上有些特殊之处，因此在开始MMD自动跟踪之前，请使用此入门笔记本进行练习，否则会耽误大量时间。\n",
        "大家也可以去参考官方教程：https://colab.research.google.com/notebooks/welcome.ipynb"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "71B6fDCJP9OB",
        "colab_type": "text"
      },
      "source": [
        "# 2.如何使用colab"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZlRs9mhsQJmV",
        "colab_type": "text"
      },
      "source": [
        "**在这里，Jupyter Notebook的操作方法也被视为“如何使用colab”。\n",
        "\n",
        "因此，它不是确切表达的一部分。请注意。"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rQWwzPeGQPZn",
        "colab_type": "text"
      },
      "source": [
        "> 1.执行程序（单元格）\n",
        "\n",
        "colab可以称为“单元程序”的单元执行处理。\n",
        "\n",
        "请把光标放在[]下面所述的浅灰色列的一部分上，当你点击单元格或鼠标移动到时，会变成三角形的播放状态"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VaSrNg5gQ0wL",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!echo \"Hello MMD Auto Trace!\"\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "j_EFqxpPRt0S",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "默认单元格状态如下：\n",
        "\n",
        "![不是焦点时](https://drive.google.com/uc?export=view&id=1Iq65BhLYQAx8vBBgdfEsLO0VeOVMjJuS)\n",
        "\n",
        "鼠标移动时或者点击单元格时:\n",
        "\n",
        "![图片](https://drive.google.com/uc?export=view&id=1_542_9rRF48Fr9TkLlERrT-1JCLG6VLU)\n",
        "\n",
        "现在您可以运行笔记本单元（程序） 点击三角形播放按钮，即可执行程序，执行状态如下(三角形为深色，周围的虚线圆正在旋转)：\n",
        "\n",
        "![执行时](https://drive.google.com/uc?export=view&id=19c52CCO_fsT7Xp86ArhUjXtcdaojrBvj)\n",
        "\n",
        "由于colab是按顺序执行的，因此存在一个等待队列的问题，如下是等待执行时的状态(三角形为灰色，周围的虚线圆正在旋转)：\n",
        "\n",
        "![等待执行时](https://drive.google.com/uc?export=view&id=15xdtGV12f_9dfdKZkPG0i4sri0b9GTlR)\n",
        "\n",
        "执行结果，会在单元格下方输出：\n",
        "\n",
        "![执行后](https://drive.google.com/uc?export=view&id=1PEcmTlmw_Y4PWWBVFsv7OHJS9_d9GEIr)\n",
        "\n",
        "注意：当您打开页面并首次运行时,由于不是官方文件，系统会要求您人工确认是否安全\n",
        "\n",
        "\n",
        "![权限申请](https://drive.google.com/uc?export=view&id=1qagK6SuKggqBCWJqDrPwqZ4XH3_IoYlL)\n",
        "\n",
        "\n",
        "注意：如果想重新开始运行，请在 **代码执行程序** 中选择 **将该运行时恢复出厂设置** 选择重置，如果没有断开与colab的会话，单纯的重启浏览器是会保留上一次的运行时环境，所有如果要还原首次执行，这里需要重置一下\n",
        "\n",
        "![替代文字](https://drive.google.com/uc?export=view&id=1F8fJLRQ2rO33aQCxPlF0v2jQxlxUP7Zp)\n",
        "\n",
        "注意:MMD自动化程序colab版本，只能运行在GPU模式下，默认也是GPU模式，但如果被修改了则会导致运行错误。\n",
        "\n",
        "因此，请确保你所处的运行环境为GPU环境，请在 **代码执行程序** 中，选择 更改 **运行时类型** ，以确认当前是否为GPU模式。\n",
        "\n",
        "\n",
        "![替代文字](https://drive.google.com/uc?export=view&id=1-ukBivmEzGIN5QZod2At374JxIXV3RD9)\n",
        "\n",
        "切换需要一点时间，右上角图标出现勾时，表示切换成功\n",
        "\n",
        "![image.png]()\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "d1CAEDaXamau",
        "colab_type": "text"
      },
      "source": [
        "# 3.如何利用google 云端硬盘输入输出"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-_XNMeqplUSB",
        "colab_type": "text"
      },
      "source": [
        "## 3.1 绑定google 云端硬盘"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Gnd7oTd-azQE",
        "colab_type": "text"
      },
      "source": [
        "MMD自动跟踪处理上传到Google云端硬盘的视频。\n",
        "\n",
        "在这里，请实际检查是否有Google云端硬盘，以及输入输出路径。\n",
        "\n",
        "1．在Google云端硬盘上创建一个名为\"autotrace\"的文件夹，并上传一个名为\"input.mp4\"的测试视频文件,大致如下：。\n",
        "\n",
        "![上传成功](https://drive.google.com/uc?export=view&id=1Pb8CdvWb1S8SF8B6bWOcEjMAbkukQwut)\n",
        "\n",
        "\n",
        "2.如果执行下面的与 **3.2 google 云端硬盘的输入单元格程序**，则将显示URL和输入字段。\n",
        "\n",
        "\n",
        "![运行时](https://drive.google.com/uc?export=view&id=1hptJQtXCWbfph2GhGAnKXlHuVHYzs7qE)\n",
        "\n",
        "\n",
        "4.单击该URL将打开一个新选项卡，在该选项卡中，将要求您提供一个使用google的帐户（如果没有，请注册）\n",
        "\n",
        "![授权1](https://drive.google.com/uc?export=view&id=1qvnjLYwj4Dfoijhpk17Ic5kGV5SpYsR9)\n",
        "\n",
        "5.选择google账号后，需要授权给colab访问权限\n",
        "\n",
        "![授权2](https://drive.google.com/uc?export=view&id=1t7Hua7_dWoF-OfRewiZMN5aovUE6x6lT)\n",
        "\n",
        "6.授权后会出现一串字符串，复制\n",
        "\n",
        "![授权3](https://drive.google.com/uc?export=view&id=1PUGf9G3G8JoEKB2c-z6Ec8rcjIMom852)\n",
        "\n",
        "7.复制字符串到之前运行的输入框中，并按ENTER确认\n",
        "![授权4](https://drive.google.com/uc?export=view&id=11yHCpmLSSSlY0mLu7-B04MlwWzD6BWDU)\n",
        "\n",
        "8.按ENTER确认后，该单元格程序，继续往下执行，正确的执行结果如下\n",
        "\n",
        "\n",
        "![确认](https://drive.google.com/uc?export=view&id=1WSAn-RsqdXk8J9H_t1bcZR9y-ij_k6xh)\n",
        "\n",
        "至此，与google云端硬盘连接完毕。\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uzIps8GqmKZO",
        "colab_type": "text"
      },
      "source": [
        "## 3.2 如何利用google云端硬盘输入"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qGCHh2Z2mUDH",
        "colab_type": "text"
      },
      "source": [
        "执行如下代码"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3n7Hgj-jbmik",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from google.colab import drive\n",
        "import os\n",
        "\n",
        "# Google文件系统，外挂新文件驱动\n",
        "drive.mount('/gdrive')\n",
        "\n",
        "# 设置MMD自动化初始文件路径\n",
        "base_path = \"/gdrive/My Drive/autotrace\"\n",
        "\n",
        "! echo \"Contents of [autotrace] folder -----------\"\n",
        "! ls \"$base_path\"\n",
        "! echo \"--------------------\"\n",
        "\n",
        "# 设置输入视频文件路径\n",
        "input_video = base_path + \"/input.mp4\"\n",
        "\n",
        "print(\"File Name: \", os.path.basename(input_video))\n",
        "print(\"File Size: \", os.path.getsize(input_video))"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Wl3nrdm6loKy",
        "colab_type": "text"
      },
      "source": [
        "## 3.3 如何利用google云端硬盘输出"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nI-YwzFtmWwJ",
        "colab_type": "text"
      },
      "source": [
        "1。如果读取成功，则接下来输出。\n",
        "\n",
        "2。尝试运行下面的单元格，如果出现 **输出成功** 表示一切OK。\n",
        "\n",
        "3.下载生成的文件，打开google硬盘，选择 autotrace 文件夹，找到output.txt，选择下载并查看内容，具体如图\n",
        "\n",
        "\n",
        "![示例](https://drive.google.com/uc?export=view&id=1Y-K7U_ZWUjT6esrO8mR9ALeBQhtqw1CT)\n",
        "\n",
        "\n",
        "注意点\n",
        "\n",
        "即使执行“删除”，保存在Google云端硬盘中的数据也只会移至回收站。\n",
        "\n",
        "在这种情况下，容量不会减少，要减少容量，请执行“清空垃圾箱”。\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HB99GB77mk3t",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from google.colab import drive\n",
        "import os\n",
        "\n",
        "# Google文件系统，外挂新文件驱动\n",
        "drive.mount('/gdrive')\n",
        "\n",
        "# 设置MMD自动化初始文件路径\n",
        "base_path = \"/gdrive/My Drive/autotrace\"\n",
        "\n",
        "with open(base_path +'/output.txt', 'w') as f:\n",
        "  f.write('Google Drive 输出成功')\n",
        "\n",
        "! echo \"autotrace文件夹内容 -----------\"\n",
        "! ls -l \"$base_path\"\n",
        "! echo \"--------------------\"\n",
        "\n",
        "! cat \"$base_path/output.txt\""
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wa6MxAB9sxSy",
        "colab_type": "text"
      },
      "source": [
        "# 生成时发生错误"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3geQmoS_s0De",
        "colab_type": "text"
      },
      "source": [
        "1.在 菜单栏的 **代码执行程序** 中选择 **重置所有代码执行程序** 选择重置，然后重新按照流程走一次\n",
        "\n",
        "2.如果上述方法仍然不行，请发送你的脚本给我或者给原作者，原作者邮箱为garnet200521358@gmail.com\n",
        "\n",
        "我的 qq811616536@gmail.com\n",
        "\n",
        "发送方式如下：\n",
        "\n",
        "（1）在菜单栏，选择复制文件到云端硬盘\n",
        "![示例](https://drive.google.com/uc?export=view&id=1vPofjZSqolLxnqzsN9jiDWQ1Cd6wXEGR)\n",
        "\n",
        "\n",
        "（2）在云端硬盘选择共享，填入共享人，并附录你遇到的问题，如果没有则一般不回复，有的话，emm......\n",
        "\n",
        "\n",
        "![示例](https://drive.google.com/uc?export=view&id=1Rl2y8eAhDRP6DGFKGZksDM9c-W2elzRC)\n",
        "\n",
        "\n",
        "![示例](https://drive.google.com/uc?export=view&id=1YGBzq1pkSaYJXHV71rtdVc5KGAUYxPex)\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AUq_TxprxXQU",
        "colab_type": "text"
      },
      "source": [
        "# 注意事项"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LBR7r6d5xaGa",
        "colab_type": "text"
      },
      "source": [
        "colab是一个可丢弃的环境。\n",
        "\n",
        "创建后，将在12小时后自动破坏环境。\n",
        "\n",
        "另外，连续30分钟没有工作，它似乎也被破坏了。\n",
        "\n",
        "如果由于执行执行的“安装完成确认”部分的单元而没有数据（没有此类文件或目录），请从执行的开始进行执行。\n",
        "\n",
        "还需要重置与Google云端硬盘的链接。\n",
        "\n",
        "但是，保存在Google云端硬盘中的数据不会被删除。\n",
        "\n",
        "建议每次重头开始执行，但是安装完成的准备数据，只需要执行一次，另外，调整参数时，最消耗时间的openpost只需要执行第一次即可，后面均不需要执行。\n",
        "\n",
        "注意目前程序只支持固定镜头的全身动作识别的视频，其他视频暂时均不受支持"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bpFKPbc1Y10s",
        "colab_type": "text"
      },
      "source": [
        "# License许可"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Hhj9yCnQZEls",
        "colab_type": "text"
      },
      "source": [
        "在发布/分发MMD自动跟踪的结果之前，请确保检查许可证。同样适用于Unity。\n",
        "\n",
        "如果您能描述一下许可证，我将不胜感激。\n",
        "\n",
        "[MMD运动跟踪自动化套件许可证](https://ch.nicovideo.jp/miu200521358/blomaga/ar1686913)\n",
        "\n",
        "中文制作---妖风瑟瑟\n",
        "\n",
        "如果有任何建议，请B站或者twitter上联系我\n",
        "\n",
        "Twitter @wolelegedaca"
      ]
    }
  ]
}